package cn.ac.ict.fpevaluation.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * 每一条原子轨迹
 *
 * @author MG
 */
public class AtomTrajectoryBean implements Cloneable{
    /**
     * 手机品牌
     */
    private String phoneBrand;
    /**
     * 文件名
     */
    private String name;
    /**
     * 方向序列
     */
    private List<Double> orientation;
    /**
     * 步长
     */
    private double stepLength;
    /**
     * 每一步
     */
    private List<StepBean> stepList;
    /**
     * 初始点
     */
    private double startX; // 每个人采集的轨迹起始点x坐标
    private double startY; // 每个人采集的轨迹起始点y坐标
    /**
     * 结束点
     */
    private double endX;
    private double endY;
    /**
     * 搜索到的所有AP
     */
    private List<List<APBean>> aps;

    public AtomTrajectoryBean() {
        stepList = new ArrayList<StepBean>();
        orientation = new ArrayList<Double>();
        aps = new ArrayList<List<APBean>>();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Double> getOrientation() {
        return orientation;
    }

    public void setOrientation(List<Double> orientation) {
        this.orientation = orientation;
    }

    public double getStepLength() {
        return stepLength;
    }

    public void setStepLength(double stepLength) {
        this.stepLength = stepLength;
    }

    public List<StepBean> getStepList() {
        return stepList;
    }

    public void setStepList(List<StepBean> stepList) {
        this.stepList = stepList;
    }

    public double getStartX() {
        return startX;
    }

    public double getStartY() {
        return startY;
    }

    public void setStartX(double startX) {
        this.startX = startX;
    }

    public void setStartY(double startY) {
        this.startY = startY;
    }

    public List<List<APBean>> getAps() {
        return aps;
    }

    public void setAps(List<List<APBean>> aps) {
        this.aps = aps;
    }

    public String getPhoneBrand() {
        return phoneBrand;
    }

    public void setPhoneBrand(String phoneBrand) {
        this.phoneBrand = phoneBrand;
    }

    public double getEndX() {
        return endX;
    }

    public void setEndX(double endX) {
        this.endX = endX;
    }

    public double getEndY() {
        return endY;
    }

    public void setEndY(double endY) {
        this.endY = endY;
    }


    public AtomTrajectoryBean cloneOne() {
        AtomTrajectoryBean ret = null;
        try {
            ret = this.clone();
            copyAps(ret);
            ret.setEndX(this.getEndX());
            ret.setStartX(this.getStartX());
            ret.setName(this.getName());
            copyOrientation(ret);
            copySteps(ret);
            ret.setStepLength(this.getStepLength());
            ret.setEndX(this.getEndX());
            ret.setEndY(this.getEndY());
            ret.setPhoneBrand(this.getPhoneBrand());
            System.out.println("EQUALS: " + (ret.getAps().hashCode() == this.hashCode()));

        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

        return ret;
    }

    @Override
    protected AtomTrajectoryBean clone() throws CloneNotSupportedException {
        return (AtomTrajectoryBean) super.clone();
    }

    private void copyAps(AtomTrajectoryBean ret) {
        List<List<APBean>> aps = new ArrayList<>();
        for (List<APBean> apBeans : this.getAps()) {
            List<APBean> item = new ArrayList<>();
            for (APBean apBean : apBeans) {
                try {
                    item.add(apBean.clone());
                } catch (CloneNotSupportedException e) {
                    e.printStackTrace();
                }
            }
            aps.add(item);
        }
        ret.setAps(aps);
    }


    private void copyOrientation(AtomTrajectoryBean ret) {

        List<Double> orientation = new ArrayList<>();
        for (Double aDouble : ret.getOrientation()) {
            double tmp = aDouble;
            orientation.add(tmp);
        }
        ret.setOrientation(orientation);

    }

    private void copySteps(AtomTrajectoryBean ret) {
        List<StepBean> stps = new ArrayList<>();
        for (StepBean stepBean : ret.getStepList()) {
            try {
                stps.add(stepBean.clone());
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
        }
        ret.setStepList(stps);
    }
}
